<?php defined('BASEPATH') OR exit('No direct script access allowed');

class admin_dashboard extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		
		if (!$this->ion_auth->logged_in())
		{
			//redirect them to the login page
			redirect('auth/login', 'refresh');
		}
		elseif (!$this->ion_auth->is_admin())
		{
			//redirect them to the home page because they must be an administrator to view this	
			redirect('/', 'refresh');
		}
		$this->load->library('email');
		$this->load->model('admin_dashboard_model');
        $this->load->library('datatables');	
         $this->load->library('form_validation');		
	}
  function index()
  { 
  $this->data['no_case']= $this->admin_dashboard_model->get_month_caseid();
   $this->data['no_nonwarrantycase']= $this->admin_dashboard_model->get_nonwarranty_case();
  $id=$this->session->userdata['user_id'];
  $this->data['no_diagnosis']= $this->admin_dashboard_model->get_month_diagnosis();
 $this->data['no_repair']= $this->admin_dashboard_model->get_month_repair();
  $this->data['engineer']=$this->admin_dashboard_model->get_engineers();
   $this->data['active_engineer']=$this->admin_dashboard_model->get_active_engineer();
 
  $this->admin_dashboard_model->insert_image($id);
  $this->data['image']=$this->admin_dashboard_model->get_image($id)->row();
  $this->data['table']=$this->admin_dashboard_model->get_detail();
   $this->data['table1']=$this->admin_dashboard_model->get_nonwarrantydetail();
  
  $meta['page_title'] = 'Call Cordinator Dashboard';
  $this->load->view('common/header',$meta);
  $this->load->view('dashboard',$this->data);
  $this->load->view('common/footer');	
  
  }
  public function ajax_detail()
  {
  
  
  
  
  }
  
  public function update_userimage()
   {
   $config['upload_path'] = './user_image/';
		$config['allowed_types'] = 'gif|jpg|png|jpeg|doc|txt|pdf|zip|rar';
		$config['max_size']	= '20480';
		$config['max_width']  = '1024';
		$config['max_height']  = '768';
		$this->load->library('upload',$config);
        $new_img =  $_FILES['user_photo']['name'];
		$id=$this->session->userdata['user_id'];
		
        $tmpName  = $_FILES['user_photo']['tmp_name'];  
       
	   $this->admin_dashboard_model->update_image($id,$new_img);
        $data =array( 'upload_data' => move_uploaded_file($tmpName,"./user_image/admin/$new_img"));
     redirect('admin/admin_dashboard');
		}
 
/*public function da()
{
$data=$this->admin_dashboard_model->get_engineer(2)->row();
echo($data->username); exit();
}*/
 public function update_profile()
{
$id=$this->session->userdata['user_id'];
$this->data['image']=$this->admin_dashboard_model->get_image($id)->row();
$this->data['profile']=$this->admin_dashboard_model->get_profile($id)->row();
 $this->admin_dashboard_model->insert_image($id);
$meta['page_title'] = 'Profile';
$this->load->view('common/header',$meta);		
$this->load->view('myprofile',$this->data);
$this->load->view('common/footer');

}
public function update_profileData()
{
$id=$this->session->userdata['user_id'];
$this->form_validation->set_rules('first_name', 'First Name', 'required|xss_clean');
$this->form_validation->set_rules('last_name', 'Last Name', 'required|xss_clean');
$this->form_validation->set_rules('email', 'Email Address', 'required|valid_email');
$this->form_validation->set_rules('phone', 'First Part of Phone', 'required|min_length[10]|max_length[10]');
$this->form_validation->set_rules('address', 'Address', 'required|xss_clean');
$this->form_validation->set_rules('company_name', 'Company Name', 'required|xss_clean');

		if ($this->form_validation->run() == true)
		{
$username = strtolower($this->input->post('first_name')) . ' ' . strtolower($this->input->post('last_name'));

$insert=array('first_name'=>$_REQUEST['first_name'],'last_name'=>$_REQUEST['last_name'],'username'=>$username,'email'=>$_REQUEST['email'],'address'=>$_REQUEST['address'],'phone'=>$_REQUEST['phone'],);

$this->admin_dashboard_model->update_profile($insert,$id);
redirect('/admin/admin_dashboard');
}
else{
redirect('/admin/admin_dashboard/update_profile');

}


}
public function test()
{
$this->load->view('common/header');		
$this->load->view('docket/test');
$this->load->view('common/footer');
}

public function get_diagnosis()
{
$data=$this->admin_dashboard_model->get_diagnosis();

}
public function get_repair()
{
$data=$this->admin_dashboard_model->get_repair();

}
public function update_company()
{
$user=$this->admin_dashboard_model->company_profile()->row();
if (isset($_POST['company']) && !empty($_POST))
{
$id=$this->input->post('id');

$insert=array('name'=>$this->input->post('name'),
              'address'=>$this->input->post('address'),
               'state'=>$this->input->post('state'),
			   'city'=>$this->input->post('city'),
			   'pincode'=>$this->input->post('pincode'),
			   'mobile'=>$this->input->post('mobile'),
			   'landline'=>$this->input->post('landline'),
			   'fax'=>$this->input->post('fax'),
			   'email'=>$this->input->post('email'),);
		
		
  $data=$this->admin_dashboard_model->update_company($insert,$id);
  redirect('admin/admin_dashboard');
}


$this->data['name'] = array(
			'name'  => 'name',
			'id'    => 'name',
			'type'  => 'text',

			'value' => $this->form_validation->set_value('name', $user->name),
		);
	$this->data['address'] = array(
			'name'  => 'address',
			'id'    => 'address',
			'type'  => 'textarea',
            'rows'   =>5,
			'value' => $this->form_validation->set_value('address', $user->address),
		);$this->data['state'] = array(
			'name'  => 'state',
			'id'    => 'state',
			'type'  => 'text',

			'value' => $this->form_validation->set_value('state', $user->state),
		);$this->data['city'] = array(
			'name'  => 'city',
			'id'    => 'city',
			'type'  => 'text',

			'value' => $this->form_validation->set_value('city', $user->city),
		);$this->data['pincode'] = array(
			'name'  => 'pincode',
			'id'    => 'name',
			'type'  => 'text',

			'value' => $this->form_validation->set_value('pincode', $user->pincode),
		);$this->data['mobile'] = array(
			'name'  => 'mobile',
			'id'    => 'mobile',
			'type'  => 'text',

			'value' => $this->form_validation->set_value('mobile', $user->mobile),
		);$this->data['landline'] = array(
			'name'  => 'landline',
			'id'    => 'landline',
			'type'  => 'text',

			'value' => $this->form_validation->set_value('landline', $user->landline),
		);$this->data['fax'] = array(
			'name'  => 'fax',
			'id'    => 'fax',
			'type'  => 'text',

			'value' => $this->form_validation->set_value('fax', $user->fax),
		);
		$this->data['email'] = array(
			'name'  => 'email',
			'id'    => 'email',
			'type'  => 'text',

			'value' => $this->form_validation->set_value('email', $user->email),
		);
			
        $this->data['id'] = array(
			'name'  => 'id',
			'id'    => 'id',
			'type'  => 'hidden',

			'value' => $this->form_validation->set_value('id', $user->id),
		);			
$meta['page_title'] = 'Company Profile';
$this->load->view('common/header',$meta);		
$this->load->view('company/company_profile',$this->data);
$this->load->view('common/footer');

}	

}	
	?>